#ifndef TEMPLE_UTIL_OWN_H_
#define TEMPLE_UTIL_OWN_H_

#include "util/stdc.h"
namespace util {

template<class T>
class own
{
public:
	own()
	{
		owned = false;
	}

	own(const own &other)
	{
		owned = other.owned;
		if (owned)
    		object = other.object;
	}

	own(own &&other)
	{
		owned = other.owned;
		if (owned)
    		object = std::move(other.object);
	}

	own(const T &obj)
	{
		owned = true;
		object = obj;
	}

	own(T &&obj)
	{
		owned = true;
		object = std::move(obj);
	}

	own &operator=(const own &other)
	{
		owned = other.owned;
		if (owned)
    		object = other.object;
		return *this;
	}

	own &operator=(own &&other)
	{
		owned = other.owned;
		if (owned)
    		object = std::move(other.object);
		return *this;
	}

	own &operator=(const T &obj)
	{
		owned = true;
		object = obj;
		return *this;
	}

	own &operator=(T &&obj)
	{
		owned = true;
		object = std::move(obj);
		return *this;
	}

	bool is_owned() const
	{
		return owned;
	}

	const T &get_refer() const
	{
		return object;
	}

private:
	T object;
	bool owned;
};

}
#endif //TEMPLE_UTIL_OWN_H_
